package com.ecfront.dao.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.ecfront.dao.GoodsImplDAO;
import com.ecfront.pojo.GoodsImpl;


/**
 * @version 1.0
 * @author www.ecfrom.com
 */

public class GoodsImplDAOImpl extends HibernateDaoSupport implements GoodsImplDAO {

	protected void initDao() {}

	public void save(GoodsImpl transientInstance) {
		getHibernateTemplate().saveOrUpdate(transientInstance);
	}


	public void delete(GoodsImpl persistentInstance) {
		getHibernateTemplate().delete(persistentInstance);
	}

	public GoodsImpl findById(java.lang.Integer id) {
		GoodsImpl instance = (GoodsImpl) getHibernateTemplate().get(
					"com.ecfront.pojo.GoodsImpl", id);
		return instance;
	}


	public List findByProperty(String propertyName, Object value) {
		String queryString = "from GoodsImpl as model where model."
					+ propertyName + "= ?";
		return getHibernateTemplate().find(queryString, value);
	}

	public List findByGiPrice(Object giPrice) {
		return findByProperty(GI_PRICE, giPrice);
	}

	public List findByGiIsRecommend(Object giIsRecommend) {
		return findByProperty(GI_IS_RECOMMEND, giIsRecommend);
	}

	public List findByGiHit(Object giHit) {
		return findByProperty(GI_HIT, giHit);
	}

	public List findAll() {
		String queryString = "from GoodsImpl";
		return getHibernateTemplate().find(queryString);
	}

	public static GoodsImplDAO getFromApplicationContext(ApplicationContext ctx) {
		return (GoodsImplDAO) ctx.getBean("GoodsImplDAO");
	}
}